# example5_3.py
import numpy as np
import os

current_dir = os.path.dirname(os.path.abspath(__file__))
csv_path = os.path.join(current_dir, "stock1.csv")

close_price, change_volume = np.loadtxt(
    csv_path,
    delimiter=",",
    usecols=(4, 6),
    unpack=True,
    skiprows=1,
)
meanS1 = np.mean(close_price)
print("收盘价算术平均值:", meanS1)
wavgS1 = np.average(close_price, weights=change_volume)
print("收盘价的加权平均值:", wavgS1)
varS1 = np.var(close_price)
print("收盘价的方差:", varS1)
medianS1 = np.median(close_price)
print("收盘价的中位数:", medianS1)
minS1 = np.min(close_price)
print("收盘价的最小值:", minS1)
maxS1 = np.max(close_price)
print("收盘价的最大值:", maxS1)
